import Vue from 'vue'
import VueRouter from 'vue-router'
// 解决路由重复报错的信息
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
const Home = () => import('views/home/Home') 
const Category = () => import('views/category/Category')
const Cart = () => import('views/cart/Cart')
const Profile = () => import('views/profile/Profile')

import Shop from 'views/shop/Shop'
import ShopList from 'views/shop/childcoms/ShopList'
import ShopDetail from 'views/shop/childcoms/ShopDetail'
import Search from 'views/search/Search'
import Login from 'views/login/Login'
import Order from 'views/order/Order'
import Account from 'views/account/Account'
// 1.注入插件
Vue.use(VueRouter)

// 2.定义路由
const routes = [
  {
    path:'/',
    redirect:'/home',
    meta:{
      showFooter:true
    }
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta:{
      showFooter: true,
      index: 1
    }
  },
  {
    path: '/product/:id',
    name: 'product',
    meta: {
      index: 3
    },
    component: () => import('views/product/ProductDetail.vue')
  },
  {
    path:'/category',
    name:'Category',
    component: Category,
    meta:{
      showFooter: true,
      index: 1
    }
  },
  {
    path:'/cart',
    name:'Cart',
    component: Cart,
    meta:{
      showFooter: true,
      index: 1
    }
  },
  {
    path:'/profile',
    name:'Profile',
    component: Profile,
    meta:{
      showFooter: true,
      index: 1
    }
  },
  {
    path:'/shop',
    name:'Shop',
    component: Shop,
    meta: {
      index: 2
    },
    children:[
      {
        path:'/shop/shoplist/:cat_id',
        name:'ShopList',
        component: ShopList,
        meta: {
          index: 3
        },
      },
      {
        path:'/shop/shopdetail/:goods_id',
        name:'ShopDetail',
        component: ShopDetail,
        meta: {
          index: 4
        },
      }
    ]
  },
  {
    path:'/search',
    name:'Search',
    component: Search,
    meta: {
      index: 2
    },
  }, 
  {
    path:'/login',
    name:'Login',
    component: Login,
    meta: {
      index: 2
    },
  },
  {
    path:'/order',
    name:'Order',
    component: Order,
    meta: {
      index: 2
    },
  },
  {
    path: '/create-order',
    name: 'create-order',
    component: () => import('views/order/CreateOrder.vue'),
    meta: {
      index: 2
    },
  },
  {
    path: '/order-detail',
    name: 'order-detail',
    component: () => import('views/order/OrderDetail.vue'),
    meta: {
      index: 3
    },
  },
  {
    path: '/address',
    name: 'address',
    component: () => import('views/address/Address.vue'),
    meta: {
      index: 2
    },
  },
  {
    path: '/address-edit',
    name: 'address-edit',
    component: () => import('views/address/AddressEdit.vue'),
    meta: {
      index: 3
    },
  },
  {
    path:'/account',
    name:'Account',
    component: Account,
    meta: {
      index: 2
    },
  }
]

// 3.创建router实例
const router = new VueRouter({
   routes
  //  mode:'history'
})


// 4.导出router实例
export default router